package settings

import "fmt"

type DBConfig struct {
	User     string `mapstructure:"user"`
	Password string `mapstructure:"password"`
	Host     string `mapstructure:"host"`
	Port     int    `mapstructure:"port"`
	DB       string `mapstructure:"db"`
	Debug    bool   `mapstructure:"debug"` // 打印全部日志
	Source   string `mapstructure:"source"`
}

func (d *DBConfig) DSN() string {
	return fmt.Sprintf(
		"%v:%v@tcp(%v:%v)/%v?charset=utf8mb4&parseTime=True",
		d.User, d.Password, d.Host, d.Port, d.DB,
	)
}
